package lion.blog.tag;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.jstl.core.LoopTagSupport;

import lion.blog.model.BlogComment;
import lion.dev.lang.MapJ;

/**
 * 
 * 文章详情评论标签
 * 
 * 
 * @author lion
 * @email hl_0074@sina.com
 * @date 2015年9月21日
 */
public class ArticleCommentListTag extends LoopTagSupport {

	private static final long serialVersionUID = 5816389169492867184L;
	private Iterator<BlogComment> items;

	@Override
	protected boolean hasNext() throws JspTagException {

		return items.hasNext();
	}

	@Override
	protected Object next() throws JspTagException {

		return items.next();
	}

	@Override
	protected void prepare() throws JspTagException {

		MapJ article = (MapJ) this.pageContext.getRequest().getAttribute("article");

		if (article == null) {
			items = new ArrayList<BlogComment>().iterator();
			return;
		}

		List<BlogComment> comments = BlogComment.list(-1, " where article=" + article.getInt("id"));
		items = comments.listIterator();
	}

}
